<?php
$pathArr = explode("/", $_SERVER["PHP_SELF"]);
$contextPath = $pathArr[1];
$rootPath = $_SERVER["DOCUMENT_ROOT"];

include $rootPath . "/" . $contextPath . "/apps/ManagerIUDS.php";
$managerIUDS = new ManagerIUDS();
$page = $_GET['page'];
if (!isset($page) && $page == "") {
	$page = 1;
}


$mode=$_GET['mode'];
if (isset($mode) && $mode == "search"){
	$productName = $_GET['product_name'];
	$listProductName = $managerIUDS->listQueryLimit($page, "product", "product_id"," WHERE product_name = '".$productName."'");
}else {
	$listProductName = $managerIUDS->listQueryLimit($page, "product", "product_id","");
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>.: Product List :.</title>
<?php
require_once("../includes/css_inc.php");
require_once("../includes/js_inc.php");
?>
<script>
	var objData = new Object();
	var breedData = new Object();
			$(document).ready(function(){ 
				$( "#product_name" ).autocomplete({
					source: function( request, response ) {
		                $.ajax({
							type: "GET",
							url: "../actions/product_action.php",
							data: {mode : "listProductData",product_name : $("#product_name").val()},
							contentType: "application/json; charset=utf-8", 
							dataType: "json",
		                    success: function( data ) {
			                        response( $.map( data, function( item ) {
			                            return {
			                                label: item.product_name,
			                                value: item.product_name
			                            }
			                        }));
		                    }
		                });
		            },
					minLength: 2
				});
			}); 
		</script>
</head>
<body>
<form name="frm1" id="frm1" action="../actions/product_action.php" method="get">
	<table width="100%" border="0">
		<tr>
        	<td align="right"> ชื่อสินค้า : 
        		<input type="text" name="product_name" id="product_name" class="higthInput">
				<input type="submit" value="ค้นหา"/>
			</td>
         </tr>	
	</table>
	<input type="hidden" name="mode" id="mode" value="searchProductList">
</form>
<table style="width: 57%" border="0">
	<thead class="ui-widget">
		<th class="ui-widget-header" colspan="3" align="left">รายการสินค้า</th>
	</thead>
	<tbody class="ui-widget-content">
		<?php
			$i = $listProductName->startLimit;
			$r = 0;
			$i = ((($page*10)+1)-10);
			if(sizeof($listProductName) > 0){
				foreach ($listProductName as $value){
			?>
			<tr >
				<td width="10%" align="center" rowspan="2"><img src="../productImage/<?=$value["product_pic_name"]?>" height="100" width="100"></td>
				<td width="16%">ชื่อสินค้า  :  </td><td><?=$value["product_name"]?></td>
			</tr>
			<tr>
				<td  valign="top">รายละเอียด  : </td><td valign="top" ><textarea cols="25" rows="5" readonly="readonly"><?=$value["product_detail"]?></textarea></td>
			</tr>
			<?php
				}//end foreach
			}//end if
			?>
		<tr>
			<td align="center" colspan="11"><?=$managerIUDS->buildPageBtn($page, $managerIUDS->getMaxPageByColumnNameForProduct("product", "product_id"))?></td>
		</tr>
	</tbody>
</table>
</body>
</html>
